//
//  QQMusicDataTool.swift
//  QQMusic
//
//  Created by xiaoyang on 16/5/4.
//  Copyright © 2016年 yangChunFu. All rights reserved.
//

import UIKit

class QQMusicDataTool: NSObject {

    
    class func getMusicList(result: (musicMs: [QQMusicModel])->()){
        
    
        //解析歌曲信息
        //1.获取文件路径,加载本地的plist文件
        guard let path = NSBundle.mainBundle().pathForResource("Musics.plist", ofType: nil) else {
            
            result(musicMs: [QQMusicModel]())
        
            return
        }
        
        //2.读取文件内容
        guard let dictArray = NSArray(contentsOfFile: path)else{
            
            result(musicMs: [QQMusicModel]())
            
            return
        }
        
        //3.解析:把字典转换成歌曲模型
        var models = [QQMusicModel]()
        
        for dict in dictArray {
            
            let model = QQMusicModel(dict: dict as! [String : AnyObject])
            
            models.append(model)
        }
        //4.返回结果粗去
        result(musicMs: models)
    }
    
}